import { login, sendMailVerificationCode, register, updatePassword } from '@/api/auth'
import { setUser } from '@/utils/userUtil'

export async function Login(account: string, password: string): Promise<void> {
  const res = (await login(account, password)) as any
  const profile: string = res.data.profile || ''
  const name: string = res.data.name || ''
  setUser(
    account,
    res.data.accessToken,
    res.data.refreshToken,
    res.data.role,
    name,
    profile,
    res.data.id
  )
}
export async function SendMailVerificationCode(userMail: string, flag: boolean): Promise<void> {
  await sendMailVerificationCode(userMail, flag)
}
export async function Register(
  userMail: string,
  password: string,
  code: string,
  role: string
): Promise<void> {
  await register(userMail, password, code, role)
}
export async function UpdatePassword(
  verificationCode: string,
  userMail: string,
  newPassword: string
): Promise<void> {
  await updatePassword(verificationCode, userMail, newPassword)
}
